package com.huabo.system.service.impl;


import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.PageInfo;
import com.huabo.system.config.DateBaseConfig;
import com.huabo.system.mysql.entity.TblImplogMySql;
import com.huabo.system.mysql.mapper.TblImplogMySqlMapper;
import com.huabo.system.oracle.entity.TblImplog;
import com.huabo.system.oracle.mapper.TblImplogMapper;
import com.huabo.system.service.TblImplogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class TblImplogServiceImpl implements TblImplogService {

    @Resource
    private TblImplogMapper tblImplogMapper;
    @Resource
    private TblImplogMySqlMapper tblImplogMySqlMapper;


    @Override
    public Map<String, Object> findByTblImplogList(String token, String staffId, String type, Integer pageNumber, Integer pageSize) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                PageInfo<TblImplog> pageInfo = new PageInfo<TblImplog>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setTlist(tblImplogMapper.findByTblImplogList(pageInfo, staff.getUsername(), type));
                pageInfo.setTotalRecord(tblImplogMapper.selectListByCount(staff.getUsername(), type));
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", pageInfo);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                TblStaffUtil staff = DealUserToken.parseUserToken(token);
                PageInfo<TblImplogMySql> pageInfo = new PageInfo<TblImplogMySql>();
                pageInfo.setCurrentPage(pageNumber);
                pageInfo.setPageSize(pageSize);
                pageInfo.setTlist(tblImplogMySqlMapper.findByTblImplogList(pageInfo, staff.getUsername(), type));
                pageInfo.setTotalRecord(tblImplogMySqlMapper.selectListByCount(staff.getUsername(), type));
                resultMap.put("code", "1");
                resultMap.put("msg", "数据访问成功");
                resultMap.put("data", pageInfo);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }
}
